﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.DAO;
using Com.CMS263.PO;
using Com.CMS263.Util;
namespace Com.CMS263.BLL
{
    public class AdminUserBLL
    {
        AdminUserDAO aud = new AdminUserDAO();
        AdminRoleBLL arll = new AdminRoleBLL();
        public void Add(AdminUser adminUser)
        {
            aud.Add(adminUser);
           
        }
        public void DeleteUserById(int id)
        {
            aud.DeleteUserById(id);
            
        }
        public void ModifyAdminUser(AdminUser adminUser)
        {
            aud.ModifyAdminUser(adminUser);
           
        }
        public IList<AdminUserDAO> GetAllAdminUser()
        {
            return aud.GetAllAdminUser();
            
        }
        public bool AdminUserLogin(string userName, string password)
        {
            AdminUser adminUser = aud.Login(userName, StringUtil.Md5(password));
            if (adminUser != null)
            {
                string power = arll.GetAdminPowerByID(adminUser.roleID);
                AdminLoginInfo li = new AdminLoginInfo(adminUser.userName, adminUser.id,adminUser.roleID,power);
                AdminLoginCookie.SaveLoginInfo(li);
                return true;
            }
            else
            {
                return false;
            }
        }


        public IList<UserList> GetUserList()
        {
            return aud.GetUserList();
        }

        public bool isExist(string userName)
        {
            return aud.isExist(userName);
        }

        public AdminUser GetAdminUserByID(int id)
        {
            return aud.GetAdminUserByID(id);
        }
    }
}
